package cn.lg.soar.redis.serializer;

import org.springframework.data.redis.serializer.RedisSerializer;
import org.springframework.data.redis.serializer.SerializationException;

/**
 * @author luguoxiang
 * 开源项目：https://gitee.com/lgx1992/lg-soar 求star！请给我star！请帮我点个star！
 */
public class BooleanRedisSerializer implements RedisSerializer<Boolean> {

    private final byte TRUE = 'T';
    private final byte FALSE = 'F';
    @Override
    public byte[] serialize(Boolean value) throws SerializationException {
        return value == null ? null : new byte[]{ Boolean.TRUE.equals(value) ? this.TRUE : this.FALSE};
    }

    @Override
    public Boolean deserialize(byte[] bytes) throws SerializationException {
        return bytes == null ? null : this.TRUE == bytes[ 0 ] ? Boolean.TRUE : Boolean.FALSE;
    }

}
